<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Metodología de la Programación II: Fichero Fuente src/Vector.cpp</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generado por Doxygen 1.5.5 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="main.html"><span>Página&nbsp;principal</span></a></li>
      <li><a href="classes.html"><span>Clases</span></a></li>
      <li class="current"><a href="files.html"><span>Archivos</span></a></li>
    </ul>
  </div>
<h1>src/Vector.cpp</h1><a href="Vector_8cpp.html">Ir a la documentación de este archivo.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
<a name="l00008"></a>00008 <span class="preprocessor">#include &lt;iostream&gt;</span>
<a name="l00009"></a>00009 <span class="preprocessor">#include &lt;cassert&gt;</span>
<a name="l00010"></a>00010 <span class="preprocessor">#include &lt;<a class="code" href="Vector_8h.html" title="Interfaz para trabajar con vectores de caracteres.">Vector.h</a>&gt;</span>
<a name="l00011"></a>00011 
<a name="l00012"></a>00012 <span class="keyword">using namespace </span>std;
<a name="l00013"></a>00013 
<a name="l00014"></a><a class="code" href="classVector.html#6f80c73b5f18dcf3f8e36065bdc8b9e5">00014</a> <a class="code" href="classVector.html#6f80c73b5f18dcf3f8e36065bdc8b9e5" title="Constructor por defecto  inicializa todo a cero.">Vector :: Vector</a>()
<a name="l00015"></a>00015 {
<a name="l00016"></a>00016         cadena=0;
<a name="l00017"></a>00017         nelem=0;
<a name="l00018"></a>00018         reservados=0;
<a name="l00019"></a>00019 }
<a name="l00020"></a>00020 
<a name="l00021"></a><a class="code" href="classVector.html#0400ebe778de707c81e56b247d99dcc0">00021</a> <a class="code" href="classVector.html#6f80c73b5f18dcf3f8e36065bdc8b9e5" title="Constructor por defecto  inicializa todo a cero.">Vector :: Vector</a>(<span class="keyword">const</span> <a class="code" href="classVector.html" title="Modulo que representa una vector de caracteres.">Vector</a> &amp; orig)
<a name="l00022"></a>00022 {
<a name="l00023"></a>00023         <span class="keywordflow">if</span> (orig.<a class="code" href="classVector.html#e319aef15424c617f005da9cb1455eab">reservados</a> == 0)
<a name="l00024"></a>00024         {
<a name="l00025"></a>00025                 cadena=0;
<a name="l00026"></a>00026                 nelem=0;
<a name="l00027"></a>00027                 reservados=0;
<a name="l00028"></a>00028         }
<a name="l00029"></a>00029         <span class="keywordflow">else</span>
<a name="l00030"></a>00030         {
<a name="l00031"></a>00031                 cadena=<span class="keyword">new</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>[orig.<a class="code" href="classVector.html#e319aef15424c617f005da9cb1455eab">reservados</a>];
<a name="l00032"></a>00032                 <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i=0; i&lt;orig.<a class="code" href="classVector.html#39c81dc21555ce54a2ad1fb6b80d125b">nelem</a>; i++)
<a name="l00033"></a>00033                         cadena[i]= orig.<a class="code" href="classVector.html#803b486477486ebfe054cc4415b9ded4">cadena</a>[i];
<a name="l00034"></a>00034                 nelem=orig.<a class="code" href="classVector.html#39c81dc21555ce54a2ad1fb6b80d125b">nelem</a>;
<a name="l00035"></a>00035                 reservados=orig.<a class="code" href="classVector.html#e319aef15424c617f005da9cb1455eab">reservados</a>;
<a name="l00036"></a>00036         }
<a name="l00037"></a>00037 }
<a name="l00038"></a>00038 
<a name="l00039"></a><a class="code" href="classVector.html#2eb3c49587a4f12cade7895ccb73f6a0">00039</a> <a class="code" href="classVector.html#2eb3c49587a4f12cade7895ccb73f6a0" title="Destructor  libera toda la memoria reservada.">Vector :: ~Vector</a>()
<a name="l00040"></a>00040 {
<a name="l00041"></a>00041         <span class="keywordflow">if</span> (reservados != 0)
<a name="l00042"></a>00042                 <span class="keyword">delete</span> [] cadena;
<a name="l00043"></a>00043 }
<a name="l00044"></a>00044 
<a name="l00045"></a><a class="code" href="classVector.html#deaf48e17e3a6d86ac05f19df58b8b37">00045</a> <span class="keywordtype">int</span> <a class="code" href="classVector.html#deaf48e17e3a6d86ac05f19df58b8b37">Vector :: GetNelem</a> ()<span class="keyword"> const</span>
<a name="l00046"></a>00046 <span class="keyword"></span>{
<a name="l00047"></a>00047         <span class="keywordflow">return</span> nelem;
<a name="l00048"></a>00048 }
<a name="l00049"></a>00049 
<a name="l00050"></a><a class="code" href="classVector.html#8d7b130e4e6b0677d5af24259b4a4bfc">00050</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="classVector.html#8d7b130e4e6b0677d5af24259b4a4bfc">Vector :: GetCaracter</a> (<span class="keywordtype">int</span> pos)<span class="keyword"> const</span>
<a name="l00051"></a>00051 <span class="keyword"></span>{
<a name="l00052"></a>00052         assert (pos&gt;=0 &amp;&amp; pos&lt;nelem);
<a name="l00053"></a>00053         <span class="keywordflow">return</span> cadena[pos];
<a name="l00054"></a>00054 }
<a name="l00055"></a>00055 
<a name="l00056"></a>00056 <span class="keywordtype">void</span> <a class="code" href="classVector.html#abd6a5b1dcca7647dccc095bcef56001" title="Lee desde la entrada estandar un texto hasta el &amp;#39;&amp;#39; (incluido).">Vector :: Leer</a> (istream &amp; is)
<a name="l00057"></a>00057 {
<a name="l00058"></a>00058         <span class="keywordtype">char</span> c;
<a name="l00059"></a>00059         <span class="keywordflow">while</span> ( (c=is.get()) != <span class="charliteral">'\0'</span>)
<a name="l00060"></a>00060         {
<a name="l00061"></a>00061                 <span class="keywordflow">if</span> (nelem == reservados)
<a name="l00062"></a>00062                         <span class="keywordflow">if</span> (reservados == 0) <a class="code" href="classVector.html#ca8c1daf1e9dd1c929a98150d5bdfa5f" title="Redimensiona el vector.">Resize</a>(2);
<a name="l00063"></a>00063                         <span class="keywordflow">else</span> <a class="code" href="classVector.html#ca8c1daf1e9dd1c929a98150d5bdfa5f" title="Redimensiona el vector.">Resize</a>(2*reservados);
<a name="l00064"></a>00064                 cadena[nelem]=c;
<a name="l00065"></a>00065                 nelem++;
<a name="l00066"></a>00066         }
<a name="l00067"></a>00067 }
<a name="l00068"></a>00068 
<a name="l00069"></a><a class="code" href="classVector.html#0ca23f0d66cb20cbc6473d63fe97fef6">00069</a> <span class="keywordtype">void</span> <a class="code" href="classVector.html#0ca23f0d66cb20cbc6473d63fe97fef6" title="Añade caracteres al vector.">Vector :: AddCaracter</a> (<span class="keywordtype">char</span> c)
<a name="l00070"></a>00070 {
<a name="l00071"></a>00071         <span class="keywordflow">if</span> (nelem == reservados)
<a name="l00072"></a>00072                 <span class="keywordflow">if</span> (reservados == 0) <a class="code" href="classVector.html#ca8c1daf1e9dd1c929a98150d5bdfa5f" title="Redimensiona el vector.">Resize</a>(2);
<a name="l00073"></a>00073                 <span class="keywordflow">else</span> <a class="code" href="classVector.html#ca8c1daf1e9dd1c929a98150d5bdfa5f" title="Redimensiona el vector.">Resize</a>(2*reservados);
<a name="l00074"></a>00074         cadena[nelem]=c;
<a name="l00075"></a>00075         nelem++;
<a name="l00076"></a>00076         crc.<a class="code" href="classCRC.html#c864495daa660086f2d5b37c894fe15f">Paridad_AddByte</a>(c);
<a name="l00077"></a>00077 }
<a name="l00078"></a>00078 
<a name="l00079"></a><a class="code" href="classVector.html#ca8c1daf1e9dd1c929a98150d5bdfa5f">00079</a> <span class="keywordtype">void</span> <a class="code" href="classVector.html#ca8c1daf1e9dd1c929a98150d5bdfa5f" title="Redimensiona el vector.">Vector :: Resize</a> (<span class="keywordtype">int</span> tam)
<a name="l00080"></a>00080 {
<a name="l00081"></a>00081         <span class="keywordflow">if</span> (tam == 0)
<a name="l00082"></a>00082         {
<a name="l00083"></a>00083                 cadena=0;
<a name="l00084"></a>00084                 nelem=0;
<a name="l00085"></a>00085                 reservados=0;
<a name="l00086"></a>00086         }
<a name="l00087"></a>00087         <span class="keywordflow">else</span>
<a name="l00088"></a>00088         {
<a name="l00089"></a>00089                 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> * aux= <span class="keyword">new</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>[tam];
<a name="l00090"></a>00090                 <span class="keywordflow">if</span> (nelem &lt;= tam)
<a name="l00091"></a>00091                         <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0; i &lt;nelem; i++)
<a name="l00092"></a>00092                                 aux[i]=cadena[i];
<a name="l00093"></a>00093                 <span class="keywordflow">else</span>
<a name="l00094"></a>00094                         <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0; i&lt;tam; i++)
<a name="l00095"></a>00095                                 aux[i]=cadena[i];
<a name="l00096"></a>00096                 <span class="keyword">delete</span> [] cadena;
<a name="l00097"></a>00097                 cadena=aux;
<a name="l00098"></a>00098                 reservados=tam;
<a name="l00099"></a>00099         }
<a name="l00100"></a>00100 }
<a name="l00101"></a>00101 
<a name="l00102"></a>00102 <span class="keywordtype">void</span> <a class="code" href="classVector.html#5d078805eaf028cdf9f811de73181126" title="Escribe en el flujo os un texto.">Vector :: Escribir</a> (ostream &amp; os)
<a name="l00103"></a>00103 {
<a name="l00104"></a>00104         <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0; i&lt;nelem; i++)
<a name="l00105"></a>00105                 os &lt;&lt; cadena[i];
<a name="l00106"></a>00106 }
<a name="l00107"></a>00107 
<a name="l00108"></a><a class="code" href="classVector.html#89ce466f6e4fcb01e64977bb469f7dee">00108</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="classVector.html#89ce466f6e4fcb01e64977bb469f7dee" title="Calculo del crc32.">Vector :: GetParidad</a> ()<span class="keyword"> const</span>
<a name="l00109"></a>00109 <span class="keyword"></span>{
<a name="l00110"></a>00110         <span class="keywordflow">return</span> crc.<a class="code" href="classCRC.html#7f073f78757f552420b1b3a4c1f309e2">Paridad_Get</a>();
<a name="l00111"></a>00111 }
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Generado el Thu Jun 10 12:36:12 2010 para Metodología de la Programación II por&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.5 </small></address>
</body>
</html>
